package com.cnzz.site1255174697.holder;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.cnzz.site1255174697.ConstHost;
import com.cnzz.site1255174697.R;
import com.cnzz.site1255174697.model.BaseEntity;
import com.cqyanyu.yanyu.view.XBaseViewHolder;
import com.facebook.drawee.view.SimpleDraweeView;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * 分类商品
 */
public class KindsGoodsGridAdapter extends BaseAdapter {

    private Context context;
    private List<BaseEntity> list;


    public KindsGoodsGridAdapter(Context context, List<BaseEntity> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public BaseEntity getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_kinds_goods, null);
        }
        SimpleDraweeView ivTop = XBaseViewHolder.get(convertView, R.id.xy_image);
        TextView tvTitle = XBaseViewHolder.get(convertView, R.id.xy_title);
        BaseEntity baseEntity = list.get(position);
        tvTitle.setText(baseEntity.getName());
        ivTop.setImageURI(ConstHost.IMG_BASE_URL + baseEntity.getIcon());
        return convertView;
    }
}
